home *** CD-ROM | disk | FTP | other *** search
- import henriautio.FPMidp;
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.Display;
- import javax.microedition.lcdui.Font;
- import javax.microedition.lcdui.Graphics;
-
- class CalcCanvas extends Canvas {
- String[] OPERATORS = new String[]{"", "+", "-", "*", "/"};
- private boolean browse = false;
- private int digits = 0;
- private int digits2 = 0;
- private boolean erase = false;
- // $FF: renamed from: f henriautio.FPMidp
- private FPMidp field_0 = new FPMidp();
- private final int CLEAR = 0;
- private final int ASNW = 1;
- private final int OPERATOR = 2;
- private int STAGE = 0;
- private static Display display;
- private static Backable goBack;
- private int prevOperator = 0;
- private String number = "";
- private String number2 = "";
- private int operator = 0;
- private boolean decimal = false;
- // $FF: renamed from: y int
- private int field_1 = 0;
- // $FF: renamed from: x int
- private int field_2 = 0;
- private String value = new String();
-
- public CalcCanvas() {
- }
-
- public void show(Display disp, Backable goBack) {
- display = disp;
- CalcCanvas.goBack = goBack;
- disp.setCurrent(this);
- }
-
- protected void paint(Graphics g) {
- this.erase = false;
- g.setColor(255, 255, 255);
- g.fillRect(0, 0, 101, 64);
- g.setColor(0, 0, 0);
- g.setFont(Font.getFont(64, 1, 8));
- g.drawString("CalcM50 v0.6", 0, 11, 0);
- g.setFont(Font.getDefaultFont());
- g.drawString("Exit", 0, 65, 0);
- g.drawString("Options", 62, 65, 0);
- if (this.browse) {
- g.drawString(this.OPERATORS[this.operator], 94, 50, 0);
- g.drawString(this.number2, 94 - (this.digits2 - 1) * 6, 37, 0);
- } else if (this.operator > 0) {
- g.drawString(this.number2, 94 - (this.digits2 - 1) * 6, 24, 0);
- g.drawString(this.OPERATORS[this.operator], 94, 37, 0);
- g.drawString(this.number, 94 - (this.digits - 1) * 6, 50, 0);
- } else if (this.digits > 0) {
- g.drawString(this.number, 94 - (this.digits - 1) * 6, 50, 0);
- } else {
- g.drawString("0", 94, 50, 0);
- }
-
- }
-
- protected void keyPressed(int keyCode) {
- this.value = (new Integer(keyCode)).toString();
- switch (keyCode) {
- case -12:
- this.erase = true;
- if (this.operator > 0 && this.digits == 0 && this.digits2 > 0) {
- this.operator = 0;
- this.number = this.number2;
- this.digits = this.digits2;
- this.digits2 = 0;
- this.number2 = "";
- this.erase = true;
- this.browse = false;
- } else if (this.digits > 0) {
- if (this.number.charAt(this.number.length() - 1) == ',') {
- this.decimal = false;
- }
-
- this.number = this.number.substring(0, this.number.length() - 1);
- --this.digits;
- if (this.number.length() == 1) {
- if (this.number.charAt(0) == '-') {
- this.number = "";
- this.digits = 0;
- }
- } else if (this.number.length() == 2 && this.number.charAt(0) == '-' && this.number.charAt(1) == '0') {
- this.number = "";
- this.digits = 0;
- }
- }
- break;
- case -11:
- if (this.digits > 0) {
- if (this.number.charAt(0) == '-') {
- this.number = this.number.substring(1, this.number.length());
- --this.digits;
- } else {
- ++this.digits;
- this.number = "-".concat(String.valueOf(String.valueOf(this.number)));
- }
- }
- break;
- case -1:
- goBack.show();
- break;
- case 35:
- if (this.digits == 1 && this.number.charAt(0) == 'E') {
- this.digits = 0;
- this.number = "";
- } else if (this.digits > 0 && this.digits2 > 0) {
- this.calculate();
- this.operator = 0;
- this.browse = false;
- } else if (this.digits > 0 || this.browse) {
- if (this.number2.length() == 0) {
- this.decimal = false;
- this.number2 = this.number;
- this.digits2 = this.digits;
- this.digits = 0;
- this.number = "";
- }
-
- this.nextOperator();
- this.erase = true;
- }
- break;
- case 42:
- this.addNumber(",");
- break;
- case 48:
- this.addNumber("0");
- break;
- case 49:
- this.addNumber("1");
- break;
- case 50:
- this.addNumber("2");
- break;
- case 51:
- this.addNumber("3");
- break;
- case 52:
- this.addNumber("4");
- break;
- case 53:
- this.addNumber("5");
- break;
- case 54:
- this.addNumber("6");
- break;
- case 55:
- this.addNumber("7");
- break;
- case 56:
- this.addNumber("8");
- break;
- case 57:
- this.addNumber("9");
- break;
- default:
- return;
- }
-
- ((Canvas)this).repaint();
- }
-
- private void nextOperator() {
- this.browse = true;
- ++this.operator;
- if (this.operator > 4) {
- this.operator = 1;
- }
-
- }
-
- private void addNumber(String s) {
- if (this.digits == 1 && this.number.charAt(0) == 'E') {
- this.number = "";
- this.digits = 0;
- }
-
- if (s.charAt(0) != ',' || !this.decimal) {
- if (this.browse) {
- this.browse = false;
- this.erase = true;
- this.prevOperator = this.operator;
- this.digits = 0;
- this.number = "";
- }
-
- if (this.digits < 10) {
- if (this.digits == 0 && s.charAt(0) == ',') {
- this.decimal = true;
- this.number = String.valueOf(String.valueOf(this.number)).concat("0,");
- this.digits += 2;
- } else if (s.charAt(0) == ',') {
- this.decimal = true;
- this.number = String.valueOf(String.valueOf(this.number)).concat(",");
- ++this.digits;
- } else {
- this.number = String.valueOf(String.valueOf(this.number)).concat(String.valueOf(String.valueOf(s)));
- ++this.digits;
- }
- }
-
- }
- }
-
- private void calculate() {
- switch (this.operator) {
- case 1:
- this.field_0.setValues(this.number, this.number2);
- this.number = this.field_0.addition();
- break;
- case 2:
- this.field_0.setValues(this.number, this.number2);
- this.number = this.field_0.subtraction();
- break;
- case 3:
- this.field_0.setValues(this.number, this.number2);
- this.number = this.field_0.multiplication();
- break;
- case 4:
- this.field_0.setValues(this.number, this.number2);
- this.number = this.field_0.division();
- break;
- default:
- return;
- }
-
- this.digits = this.number.length();
- this.number2 = "";
- this.digits2 = 0;
- this.operator = 0;
- this.decimal = false;
- this.erase = true;
- this.browse = false;
- }
- }
-